home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / include / intcvt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-17  |  3.0 KB  |  96 lines

  1. /* @(#)intcvt.h    1.1 99/10/18 Copyright 1986 J. Schilling */
  2. /*
  3.  *    Definitions for conversion to/from integer data types of various size.
  4.  *
  5.  *    Copyright (c) 1986 J. Schilling
  6.  */
  7. /*
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2, or (at your option)
  11.  * any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; see the file COPYING.  If not, write to
  20.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #ifndef    _INTCVT_H
  24. #define    _INTCVT_H
  25.  
  26.  
  27. #define    i_to_2_byte(a, i)    (((Uchar *)(a))[0] = ((i) >> 8) & 0xFF,\
  28.                  ((Uchar *)(a))[1] = (i) & 0xFF)
  29.  
  30. #define    i_to_3_byte(a, i)    (((Uchar *)(a))[0] = ((i) >> 16)& 0xFF,\
  31.                  ((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\
  32.                  ((Uchar *)(a))[2] = (i) & 0xFF)
  33.  
  34. #define    i_to_4_byte(a, i)    (((Uchar *)(a))[0] = ((i) >> 24)& 0xFF,\
  35.                  ((Uchar *)(a))[1] = ((i) >> 16)& 0xFF,\
  36.                  ((Uchar *)(a))[2] = ((i) >> 8) & 0xFF,\
  37.                  ((Uchar *)(a))[3] = (i) & 0xFF)
  38.  
  39.  
  40.  
  41. #define    a_to_byte(a)        (((Int8_t*) a)[0])
  42.  
  43. #define    a_to_u_byte(a)        ((UInt8_t) \
  44.                 (((Uchar*) a)[0]       & 0xFF))
  45.  
  46. #define    a_to_u_2_byte(a)    ((UInt16_t) \
  47.                 ((((Uchar*) a)[1]       & 0xFF) | \
  48.                  (((Uchar*) a)[0] << 8  & 0xFF00)))
  49.  
  50. #define    a_to_2_byte(a)        (int)(Int16_t)a_to_u_2_byte(a)
  51.  
  52. #define    a_to_u_3_byte(a)    ((Ulong) \
  53.                 ((((Uchar*) a)[2]       & 0xFF) | \
  54.                  (((Uchar*) a)[1] << 8  & 0xFF00) | \
  55.                  (((Uchar*) a)[0] << 16 & 0xFF0000)))
  56.  
  57. #define    a_to_3_byte(a)        a_to_u_3_byte(a)    /* XXX Is there a signed version ? */
  58.  
  59. #ifdef    __STDC__
  60. #    define    __TOP_4BYTE    0xFF000000UL
  61. #else
  62. #    define    __TOP_4BYTE    0xFF000000
  63. #endif
  64.  
  65. #define    a_to_u_4_byte(a)    ((Ulong) \
  66.                 ((((Uchar*) a)[3]       & 0xFF) | \
  67.                  (((Uchar*) a)[2] << 8  & 0xFF00) | \
  68.                  (((Uchar*) a)[1] << 16 & 0xFF0000) | \
  69.                  (((Uchar*) a)[0] << 24 & __TOP_4BYTE)))
  70.  
  71. #define    a_to_4_byte(a)        (long)(Int32_t)a_to_u_4_byte(a)
  72.  
  73.  
  74. #define    la_to_u_2_byte(a)    ((UInt16_t) \
  75.                 ((((Uchar*) a)[0]       & 0xFF) | \
  76.                  (((Uchar*) a)[1] << 8  & 0xFF00)))
  77.  
  78. #define    la_to_2_byte(a)        (int)(Int16_t)la_to_u_2_byte(a)
  79.  
  80. #define    la_to_u_3_byte(a)    ((Ulong) \
  81.                 ((((Uchar*) a)[0]       & 0xFF) | \
  82.                  (((Uchar*) a)[1] << 8  & 0xFF00) | \
  83.                  (((Uchar*) a)[2] << 16 & 0xFF0000)))
  84.  
  85. #define    la_to_3_byte(a)        la_to_u_3_byte(a)    /* XXX Is there a signed version ? */
  86.  
  87. #define    la_to_u_4_byte(a)    ((Ulong) \
  88.                 ((((Uchar*) a)[0]       & 0xFF) | \
  89.                  (((Uchar*) a)[1] << 8  & 0xFF00) | \
  90.                  (((Uchar*) a)[2] << 16 & 0xFF0000) | \
  91.                  (((Uchar*) a)[3] << 24 & __TOP_4BYTE)))
  92.  
  93. #define    la_to_4_byte(a)        (long)(Int32_t)la_to_u_4_byte(a)
  94.  
  95. #endif    /* _INTCVT_H */
  96.